package 剑指offer;

import java.util.Stack;

public class _31栈的压入弹出序列 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        boolean bPossible = false;
        if(pushed != null && popped != null && pushed.length != popped.length ) {
            return false;
        }
        int length = pushed.length;
        int i = 0;
        int j = 0;
        Stack<Integer> stackData = new Stack<>();

        for(; i < length; i++) {
            stackData.push(pushed[i]);

            while(!stackData.empty() && stackData.peek() == popped[j]) {
                stackData.pop();
                j++;
            }

        }
        if(stackData.isEmpty()) {
            return true;
        }
        return false;
    }
}
